const axios = require("axios");
const cheerio = require("cheerio");

// 获取评测游戏卡片数据
async function getYouxiaGameJudgeCard() {
  const res = await axios.get("https://www.ali213.net/news/");
  return parseGameGameJudgeCard(res.data);
}

function parseGameGameJudgeCard(page) {
  const $ = cheerio.load(page);
  const dataList = [];
  $(".smleft .blockbox .itemout").each(function () {
    const item = {};
    item.link = $("a", this).attr("href");
    item.img = $("a img", this).attr("src");
    item.name = $("a img", this).attr("alt");
    item.author = $("a .pcinfo .i2 span", this).text();
    item.time = $("a .pcinfo .i2 em", this).text();
    item.introduce = $("a .pcinfo .i3", this).text();
    item.Bscore = $("a  .pfbox span", this).text();
    item.Sscore = $("a  .pfbox i", this).text();
    item.tags = [];
    $("a .pcinfo .i4 span", this).each(function () {
      item.tags.push($(this).text());
    });
    dataList.push(item);
  });
  return dataList;
}

module.exports = getYouxiaGameJudgeCard;
